/*
 * Create Author  : jinpeng.chen
 * Create Date    : 2018-10-16
 * Project        : designpattern-learn
 * File Name      : MemberPriceStrategyProcessors.java
 *
 * Copyright (c) 2010-2018 by 18Birdies, LLC.
 * All Rights Reserved.
 *
 */
package com.charles.designpattern.strategy;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;

/**
 * 功能描述:  <p>
 *
 * @author : jinpeng.chen <p>
 * @version 1.0 2018-10-16
 * @since designpattern-learn 1.0
 */
@Component
public class MemberPriceStrategyProcessors {

  private Map<MemberLevel, MemberStrategy> memberStrategyMap;

  @Autowired
  public void setMemberStrategyMap(final List<MemberStrategy> memberStrategyList) {
    Preconditions.checkArgument(!CollectionUtils.isEmpty(memberStrategyList));
    memberStrategyMap = Maps.newHashMap();

    memberStrategyList.forEach(strategy -> {
      memberStrategyMap.put(strategy.getMemberLevel(), strategy);
    });
  }

  public MemberStrategy getStrategyProcessor(MemberLevel memberLevel) {
    return memberStrategyMap.get(memberLevel);
  }
}
